package cn.com.dashihui.web.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresAuthentication;

import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

import cn.com.dashihui.web.base.BaseController;
import cn.com.dashihui.web.service.UserDataService;

@RequiresAuthentication
public class UserDataController extends BaseController{
	private UserDataService service = new UserDataService();
	/**
	 * 查询分公司列表
	 */
    public void index(){
        render("index.jsp");
    }
  //统计列表
	public void page(){
		int pageNum = getParaToInt(0, 1);
		int pageSize = getParaToInt("pageSize", PropKit.getInt("constants.pageSize"));
		Page<Record> page=service.basepage(pageNum, pageSize);
		List<Record> baselist=page.getList();
		for (Record record : baselist) {
			Record order=service.orderPage(record.getStr("wxids"), record.getStr("creatMonth"));
			if(order!=null){
				record.setColumns(order);
				record.set("userids", null).set("wxids", null);
				record.set("othnum",order.getLong("validnum")-order.getLong("prenum")-order.getLong("backnum"));
				record.set("oldnum",order.getLong("allnum")-order.getLong("newnum"));
			}
		}
		renderResult(0,page);
	}


	//商品详情
	public void goodsDetail(){
		int pageNum = getParaToInt(0, 1);
		int pageSize = getParaToInt("pageSize", PropKit.getInt("constants.pageSize"));
		String month=getPara("month");
		int type=getParaToInt("type");
		int sum=0;
		Page<Record> page=service.goodsDetail(pageNum, pageSize, month, type);
		List<Record> goodslist=page.getList();
		for (Record record : goodslist) {
			sum+=record.getLong("usNum").intValue();
		}
		renderResult(0,String.valueOf(sum),page);
	}
	
	
}